package com.adcc.monitoragent.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * ip + port 唯一确定 消息队列监控类，包括activeMq apolloMq等
 * 
 * @author charlie
 * 
 */
public class MqBean extends BaseBean {
	private static final long serialVersionUID = 1L;
	private  String fixType = "mq";
	private String type;// 类型
	private String id;// ID标识
	private String version;// 服务版本
	private String port;// 端口
	private String ipCluster;//集群ip
	private String portCluster;// 集群端口
	private String testConnUrl;// 测试连接
	private List<MqMetricsBean> metrics = new ArrayList<MqMetricsBean>();// 队列
	/**
	 * activemq类型
	 */
	public static final String MQ_TYPE_ACTIVE = "MQ_TYPE_ACTIVE";
	/**
	 * 东方通mq类型
	 */
	public static final String MQ_TYPE_TLRT = "MQ_TYPE_TLRT";
	/**
	 * queue类型
	 */
	public static final String MQ_MODE_QUEUE = "queue";
	/**
	 * topic类型
	 */
	public static final String MQ_MODE_TOPIC = "topic";

	public MqBean() {
		super();
	}

	public MqBean(String key) {
		super();
		String[] temp = key.split(":");
		if(temp.length == 2) {
			this.ip = temp[0];
			this.port = temp[1];
		}
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public List<MqMetricsBean> getMetrics() {
		return metrics;
	}
	
	public void setMetrics(List<MqMetricsBean> metrics) {
		this.metrics = metrics;
	}

	public String getIpCluster() {
		return ipCluster;
	}

	public void setIpCluster(String ipCluster) {
		this.ipCluster = ipCluster;
	}

	public String getPortCluster() {
		return portCluster;
	}

	public void setPortCluster(String portCluster) {
		this.portCluster = portCluster;
	}

	/**
	 * 消息队列中的队列监控
	 * @author charlie
	 *
	 */
	public static class MqMetricsBean extends BaseBean {
		private static final long serialVersionUID = 1L;  
		/**
		 * 固定窜
		 */
		private  String fixType = "mq_metric";
		private String remark;//备注
		private String name;//名称
		private String producer;//生产者数量
		private String consumer;//消费者数量
		private String enqueue;//队列消息数量
		private String dequeue;//已传递消息数量
		private String dequeuePer = "0";//单位时间已传递消息   链路是否断开判断依据
		private String size;//现持有消息数量
		private String type = MQ_MODE_QUEUE;
		public String getRemark() {
			return remark;
		}
		public void setRemark(String remark) {
			this.remark = remark;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getProducer() {
			return producer;
		}
		public void setProducer(String producer) {
			this.producer = producer;
		}
		public String getConsumer() {
			return consumer;
		}
		public void setConsumer(String consumer) {
			this.consumer = consumer;
		}
		public String getEnqueue() {
			return enqueue;
		}
		public void setEnqueue(String enqueue) {
			this.enqueue = enqueue;
		}
		public String getDequeue() {
			return dequeue;
		}
		public void setDequeue(String dequeue) {
			this.dequeue = dequeue;
		}
		public String getSize() {
			return size;
		}
		public void setSize(String size) {
			this.size = size;
		}
		public String getType() {
			return type;
		}
		public void setType(String type) {
			this.type = type;
		}
		public String getFixType() {
			return fixType;
		}
		public String getDequeuePer() {
			return dequeuePer;
		}
		public void setDequeuePer(String dequeuePer) {
			this.dequeuePer = dequeuePer;
		}
		
		@Override
		public String toString() {
			return "MqMetricsBean [remark=" + remark + ", name=" + name
					+ ", producer=" + producer + ", consumer=" + consumer
					+ ", enqueue=" + enqueue + ", dequeue=" + dequeue
					+ ", dequeuePer=" + dequeuePer + ", size=" + size
					+ ", type=" + type + "]";
		}
		public String buildKey() {
			return "/" + this.type + "/" + this.name;
		}
		public void setShowName() {
			setShowName(name);
		}
	}

	public String getTestConnUrl() {
		return testConnUrl;
	}

	public void setTestConnUrl(String testConnUrl) {
		this.testConnUrl = testConnUrl;
	}

	@Override
	public String toString() {
		return "MqBean [fixType=" + fixType + ", type=" + type + ", id=" + id
				+ ", version=" + version + ", port=" + port + ", ipCluster="
				+ ipCluster + ", portCluster=" + portCluster + ", testConnUrl="
				+ testConnUrl + ", metrics=" + metrics + "]";
	}

	public String getFixType() {
		return fixType;
	}
	/**
	 * 获取关键字唯一标识
	 * @return
	 */
	public String buildKey() {
		return this.ip + ":" + this.port;
	}
	/**
	 * 获取集群mq唯一标识
	 * @return
	 */
	public String buildClusterKey() {
		return this.ipCluster + ":" + this.portCluster;
	}
	/**
	 * 获取展现名称   ip+_+port
	 */
	public void setShowName() {
		setShowName("Mq");
	}
}
